import Cookie from 'js-cookie';

export const getCookie = (key: string) => {
  return Cookie.get(key);
};

export const setCookie = (key: string, value: string, option?: Record<string, unknown> | null) => {
  Cookie.set(key, value, { path: '/', ...option });
};

export const removeCookie = (key: string, option: Record<string, unknown> = {}) => {
  Cookie.remove(key, { ...option });
};
const TokenName = 'token';
export const getToken = () => {
  const token = getCookie(TokenName) || localStorage.getItem(TokenName);
  return token === null || token === undefined || token.length === 0 ? null : token;
};
export const setToken = (token: string) => {
  setCookie(TokenName, token);
};
export const removeToken = () => {
  Cookie.remove(TokenName, { path: '/' });
  localStorage.removeItem(TokenName);
};
